<?php
/**
 * flexslider
 * http://www.woothemes.com/flexslider/
 *
 * @author danidhsm
 *
 */
class flexslider extends CI_Controls{

	/**
	 *
	 * Enter Array con solo el nombre de la imagen que se le pasará al control
	 * @var array
	 */
	public $images;

	public $thumbs;
	
	public $speed;
	
	/*
	 * slide,fade,none,kick,transfer,shuffle,explode,turnOver,chewyBars
	 */
	public $animation='fade';
	
	function __construct(){
		parent::__construct();
		$this->images=array();
		$this->speed=7000;
	}

	function drawContent(){



		$div= new div();
		$div->atributos=$this->atributos;
		$div->att('class','flexslider '.$this->att('class'));
		
		$ul= new ul();
		$ul->atributos=$this->heredarAtributos('_ul');
		$ul->att('class','slides '.$this->att('class'));

		//creo la estructura

		$imagenes=$this->images;
		$nimagenes=count($imagenes);
		for($i=0;$i<$nimagenes;++$i){
			$li=new li();
			$li->att('id','liimg_'.$i);
			$li->att('class','flexsliderli');
			if(!empty($this->thumbs)){
				$li->att('data-thumb',$this->thumbs[$i]);
			}
			$img=new img();
			$img->att('id','img_'.$i);
			$img->att('class','flexslider_image');
			$img->att('src',$imagenes[$i]);
			$li->addControl($img);
			$ul->addControl($li);
		}
		
		$div->addControl($ul);
		
		$this->flexSlider_script();
		return $div;

	}

	private function flexSlider_script(){

		$this->CI->dynamic_assets->add_js(base_url('js/vendor/flexslider/jquery.flexslider-min.js'));
		$this->CI->dynamic_assets->add_js(base_url('js/vendor/easing.js'));
		$this->CI->dynamic_assets->add_js(base_url('js/vendor/mousewheel.js'));
		
		$this->CI->dynamic_assets->add_css(base_url('js/vendor/flexslider/flexslider.css'));
		
		
		ob_start();
		?>
		<script>

		$(document).ready(function() {
			$('#<?php echo $this->att('id');?>').flexslider({
				animation: '<?php echo $this->animation; ?>',
			    //controlNav: "thumbnails",
			    slideshowSpeed: <?php echo $this->speed ;?>,
				selector: '#<?php echo $this->att('id'); ?>_ul > li'
			});
		});
			
		</script>
		<?php
		
		$this->CI->dynamic_assets->add_code_js(ob_get_clean());
			
	}
}